package com.cz.common.utils;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.apache.http.HttpResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HikvisionApiUtil {
    public static Map<String,String> vehicleTypeMap =new HashMap();
    static {
        vehicleTypeMap.put("unknown","轿车");
        vehicleTypeMap.put("largeBus","大型客车");
        vehicleTypeMap.put("truck","货车");
        vehicleTypeMap.put("vehicle","轿车");
        vehicleTypeMap.put("van","面包车");
        vehicleTypeMap.put("buggy","小货车");
        vehicleTypeMap.put("pedestrian","行人");
        vehicleTypeMap.put("twoWheelVehicle","二轮车");
        vehicleTypeMap.put("threeWheelVehicle","三轮车");
        vehicleTypeMap.put("SUVMPV","SUV/MPV");
        vehicleTypeMap.put("mediumBus","中型客车");
        vehicleTypeMap.put("motorVehicle","机动车");
        vehicleTypeMap.put("nonmotorVehicle","非机动车");
        vehicleTypeMap.put("smallCar","小型轿车");
        vehicleTypeMap.put("miniCar","微型轿车");
        vehicleTypeMap.put("pickupTruck","皮卡车");
        vehicleTypeMap.put("saloon","轿车");
        ArtemisConfig.host = "192.168.0.2"; // 平台/nginx的IP和端口（必须使用https协议，https端口默认为443）
        ArtemisConfig.appKey = "29856495"; // 秘钥appkey
        ArtemisConfig.appSecret = "P14xgVsmFnm8eJjVRlvU";// 秘钥appSecret
    }
    private static final String ARTEMIS_PATH = "/artemis";

    public static List<String> eventIdList = new ArrayList<>();

    //获取卡口设备列表
    public static Map monitoringPointDevice(){
        JSONObject request = new JSONObject();
        request.put("pageNo",1);
        request.put("pageSize",20);
        String body= JSON.toJSONString(request);
        String dataApi = ARTEMIS_PATH +"/api/resource/v1/monitoringPointDevice/get";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",dataApi);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        Map maps = (Map) JSON.parse(result);
        String resultCode=maps.get("code").toString();
        if(resultCode.equals("0")){
            return maps;
        }else {
            System.err.println("获取卡口列表错误------"+maps.get("msg").toString());
        }
        return null;
    }
    //获取抓拍事件列表
    public static Map illegalEvents(String beginTime, String endTime){
        JSONObject request = new JSONObject();
        request.put("pageNo",1);
        request.put("pageSize",500);
        request.put("beginTime",beginTime);
        request.put("endTime",endTime);
        String body= JSON.toJSONString(request);
        String dataApi = ARTEMIS_PATH +"/api/mpc/v1/events/vehicleRecord";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",dataApi);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,"application/json");
        Map maps = (Map) JSON.parse(result);
        String resultCode=maps.get("code").toString();
        if(resultCode.equals("0")){
            return maps;
        }else {
            System.err.println("获取抓拍事件错误------"+maps.get("msg").toString());
        }
        return null;
    }

    //获取抓拍车辆图片
    public static HttpResponse eventsImage(String aswSyscode, String picUri){
        JSONObject request = new JSONObject();
        request.put("aswSyscode",aswSyscode);
        request.put("picUri",picUri);
        String body= JSON.toJSONString(request);
        String dataApi = ARTEMIS_PATH +"/api/mpc/v1/events/image";
        Map<String,String> path = new HashMap<String,String>(2){
            {
                put("https://",dataApi);
            }
        };
        HttpResponse response=ArtemisHttpUtil.doPostStringImgArtemis(path,body,null,null,"application/json",null);
        response.getLocale();
        return response;
    }


}
